import { Http,Headers,Jsonp, } from '@angular/http';
import { Injectable} from '@angular/core';
import { Cred } from '../providers/global';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';
import { HttpClient,HttpHeaders } from '@angular/common/http';

@Injectable()

export class GetMusicService{
    
    uurl = 'http://www.zhengshangfeng.xin';
    constructor(public http: Http,public jsonp:Jsonp,public Http: HttpClient,) {
        this.http = http;
    }
   
    getId(){
        let url = this.uurl + '/getMusic.php';
        let headers = new Headers();
        return this.http.get(url,{headers:headers});
    }
    
    getMusic(id) {
        let url = '/assets/json/music/'+id+'.json'
        let headers = new Headers();
        return this.http.get(this.uurl + url,{headers:headers});
            
    }
    searchMusic(name){
        let headers = new Headers();
        // let url = 'http://s.music.163.com/search/get/?src=lofter&type=1&filterDj=true&s=' + name +'&limit=5&offset=0';
        let url = '/assets/json/'+name+'.json';
        // let headers = new Headers();
        // headers.append('Content-Type', 'application/json');
        return this.http.get(this.uurl +url,{headers:headers});
    }

    search(name){
        
        let headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        return this.http.get(this.uurl + '/test.php?name='+ name,{headers:headers});
    }
    
    searchFresh(){
        let headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        return this.http.get(this.uurl + '/filelist.php',{headers:headers});
    }

    searchRes(){
        let headers = new HttpHeaders();
        return this.Http.get<any[]>('assets/json/data/filelist.json',{headers:headers})
        .toPromise()
        .then(res => <any[]>res)
        .then(data => { return data; });
    }

    add(id){
        let headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        return this.http.get(this.uurl + '/music.php?id='+ id,{headers:headers});
    }
    delete(id){
        let headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        return this.http.get(this.uurl + '/delete.php?id='+ id,{headers:headers});
    }

}
